#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
using ll = long long;
const int N=1e6+10;

int main() {
    ll n, m;
    scanf("%lld%lld",&n,&m);
    vector<vector<ll>> arr(n+1,vector<ll>(m+1));
    vector<ll> row(n+1),col(m+1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            scanf("%lld", &arr[i][j]);
            row[i]+=arr[i][j];
            col[j]+=arr[i][j];
        }

    }


    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
            printf("%lld ",row[i] + col[j] - arr[i][j]);
        printf("\n");
    }

    return 0;
}

